<?php
    session_start();    
    if($_POST)://formular odeslan
        if($_POST['spam']!=$_SESSION['frmEmail_token'])://vyplnil robot
            echo "Vypršela platnost formuláře."."\n";
            header('Location:../index.php?id=frmContacts');
        else://nevyplnil robot    
            //TODO tady zavolame tridu email 
            
            if(empty($_POST['txtName'])):
                $err=true;
            elseif (empty($_POST['txtEmail'])):
                $err=true;
            elseif (empty($_POST['txtSubject'])):
                $err=true;
            elseif (empty($_POST['txtBody'])):
                $err=true;
            else:
                $err=false;
            endif;

            if($err==false):
                
                $_SESSION['vName']=$_POST['txtName'];
                $_SESSION['vEmail']=$_POST['txtEmail'];
                $_SESSION['vSubject']=$_POST['txtSubject'];
                $_SESSION['vBody']=$_POST['txtBody'];
            
                require_once '../php/MyEmail.php';
                $iMail = new MyEmail($_SESSION['vEmail'], $_SESSION['vName'].'-'.$_SESSION['vEmail'].'-'.$_SESSION['vSubject'], $_SESSION['vBody']);
                $valid=$iMail->ValidateForm($_SESSION['vName'], $_SESSION['vEmail']);
                if ($valid=='')://data validni, odesli email
                    $iMail->Send();
                    echo $valid;
                    header('Location:../index.php?id=frmEmailSend');
                else:
                    echo $valid;
                endif;              
            else:
                echo "<script>window.alert('Formular neni spravne vyplnen.');window.location.href='../index.php?id=frmContacts';</script>";
            endif;           
        endif;
    endif;        
?>